<!-- 复制组件 -->

<style lang="scss" scoped>
.copy-item {
  display: inline-block;
}
</style>

<template>
  <div v-if="value && value !== ''" class="copy-item" :class="{ 'link-type': isLinkType }" @click="handelClick"><span v-if="title !== ''" class="c909399">{{ title }}</span>{{ value }} <i v-if="value" data-clipboard-action="copy" class="el-icon-copy-document" @click.stop="copyText(value, $event)" /></div>
</template>

<script>
import copyText from '@/utils/common'
import _ from 'lodash'

export default {
  name: 'CopyItem',
  props: {
    title: {
      type: String,
      default: ''
    },
    value: {
      type: String,
      default: ''
    }
  },

  data() {
    return {
      isLinkType: false
    }
  },

  created() {
    this.isLinkType = _.has(this, '$listeners.click')
  },

  methods: {
    handelClick() {
      if (!this.isLinkType) return
      this.$emit('click')
    },

    copyText
  }
}
</script>
